package org.example.config;

import feign.hystrix.FallbackFactory;
import org.example.service.RouteFeignService;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class RouteClientServiceFallbackFactory implements FallbackFactory {
    @Override
    public RouteFeignService create(Throwable throwable) {
        return new RouteFeignService() {
            @Override
            public void a(HttpServletResponse response) {
                System.out.println("客户端提供了降级，这个服务已经关闭");
                try {
                    response.sendRedirect("http://localhost:8001/doc.html#/home");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void b(HttpServletResponse response) {
                System.out.println("客户端提供了降级，这个服务已经关闭");
                try {
                    response.sendRedirect("http://localhost:8002/doc.html#/home");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };
    }
}
